<template>
	<view>
		
		<view class="more">
			<view class="mo">
				<view class="mo_01">{{ lou }}薪资审核</view>
			</view>
		</view>


		<view class="timeblock">
			<view v-for="(item, index) in time" class="timeblock-time" :key="index">
				<view class="">
					{{ item.time }}
					<text style="margin-left: 20rpx;font-weight: bold;">共计{{ item.total }}单</text>
				</view>
				<view class="timeblock-people" v-for="(peoitem, index1) in item.list">
					<view>{{ peoitem.lname }}</view>
					<view>系统记录{{ peoitem.count }}单</view>
					<view @click="toShow(index,index1)">实际送{{ peoitem.scount==null?peoitem.count:peoitem.scount }}单</view>
					<view style="font-weight: bold;">PS:{{ peoitem.remark }}</view>
				</view>
			</view>
		</view>




		<view class="peoplemoney">
			<view class="" style="margin-bottom:20rpx;font-size: 32rpx;font-weight: bold">楼栋长统计：</view>
			<view v-for="(item, index) in totalpeoplelist" class="peoplemoney-people" :key="index">
				<view>{{ item.lname }}</view>
				<view>实际送{{item.count}}单</view>
				<view>应发{{item.ymoney}}元</view>
				<view>奖励{{item.jmoney}}元</view>
				<view>实发{{item.smoney}}元</view>
				<view style="font-weight: bold;">PS:{{ item.tips }}</view>
			</view>
		</view>
		
		
		
		<!-- //提交 -->
		<view class="login__info__item__button tn-cool-bg-color-15--reverse" hover-class="tn-hover" :hover-stay-time="150" @tap="confirm()">
			提交
		</view>
		
	
		<!-- //修改底薪弹窗 -->
		<u-popup v-model="show" :closeable="true" @close="oneclose()" mode="bottom" border-radius="14">
			<view class="" style="width: 100%; height: 400rpx; display: flex;flex-direction: column; padding: 40rpx 30rpx 10rpx 30rpx;">
				<!-- //信息头衔 -->
				<view class="" style="display: flex;">
					<view class="text-xxl text-bold text-black">身份:{{name}}{{timeps}}</view>
				</view>
				<view class="margin-top-lg" style="display: flex;align-items: center; width: 100%;">
					<text class="text-xl text-bold">实际送的单量：</text>
					<input class="text-red text-bold " type="number" @input="scountInput" placeholder-class="placeholder" :value="scount" />
				</view>
				<!-- //功能按钮 -->
				<view class="bottom-button" style="margin-top: 30rpx">
					<button class="bg-gradual-blue" style="width: 100%;" @click="setMoneySet()">保存</button>
				</view>
			</view>
		</u-popup>
		
	</view>
</template>

<script>
export default {
	data() {
		return {
			pindex: 0,
			sindex: 0,
			name: '',
			timeps: '',
			scount: 0,
			show: false,
			fopenid: 'oryqr6fcWZdnLWZ6OYa1NzymSza0',
			fname: "胡必成",
			lou: '升华公寓35栋',
			timelist:[
				'11:00~11:20',
				'11:20~11:40',
				'11:40~12:00',
				'12:00~12:20',
				'12:20~12:40',
				'12:40~13:00'
			],
			time: [
				{
					lou: '',
					time: '11:00~11:20', //趟次
					total: 20,
					list: [
						{
						    id: null,
						    lopenid: "oryqr6fcWZdnLWZ6OYa1NzymSza0",
						    lname: '胡必成',
						    louname: "升华公寓34栋",
						    givetime: "12:00~12:20",
						    count: 1,
						    school: 0,
						    remark: "实际送了6单",
						    scount: 2,
						    ostatus: null
						},
					]
				}
			],
			totalpeoplelist: [
				{
				    lou:'升华公寓35栋',
					name: '张三',
					actualnum: 40, //实际送多少单
					ymoney: 40, //应发多少钱
					reward: 0, //奖励
					smoney: 40, //实发薪资
					tips: '' //备注
				},
				{
					lou:'升华公寓35栋',
					name: '李四',
					actualnum: 40, //实际送多少单
					ymoney: 40, //应发多少钱
					reward: 0, //奖励
					smoney: 40, //实发薪资
					tips: '' //备注
				}]
			
		};
	},
	//加载
	onLoad() {
		let that = this;
		that.initLouOrder();
	},
	methods: {
		//初始化
		initLouOrder(){
			let that = this;			
			that.timelist.unshift(that.lou);
			console.log(that.timelist)
			uni.request({
				url:"https://zback.shixiaozhu.work/ShixiaozhuTest/orderParticipant/getLouOrder",
				header: {
				      'content-type': 'application/json'
				     },
				method:"POST",
				data: that.timelist,
				success(res) {
					if(res.data.status==200){
						console.log("输出：",res.data.data)
					    that.time = res.data.data;
						that.totalMoney();
					}else{
						
					}
				}
			})
		},
		//统计人员名单
		totalMoney(){
			let that = this;
			let newPeopleList = [];
			let slistOpenidlist = [];
			for (var i = 0; i < that.time.length; i++) {
				for (var j = 0; j < that.time[i].list.length; j++) {
					if(slistOpenidlist.indexOf(that.time[i].list[j].lopenid) == -1){
						 slistOpenidlist.push(that.time[i].list[j].lopenid);
						 var item = {}
						 item.lname=  that.time[i].list[j].lname 
						 // item.givetime = that.time[i].list[j].givetime
						 item.school = that.time[i].list[j].school
						 item.remark = that.time[i].list[j].remark
						 item.lopenid = that.time[i].list[j].lopenid
						 item.count = that.time[i].list[j].scount
						 // item.scount = that.time[i].list[j].scount
						 item.ymoney = that.time[i].list[j].scount;
						 item.jmoney = 0;
						 item.smoney = that.time[i].list[j].scount;
						 item.fopenid = that.fopenid;
						 item.louname = that.time[i].list[j].louname;
						 item.fname = that.fname;
						 item.ostatus = 0;
						 newPeopleList.push(item);
					}else{
					    newPeopleList[slistOpenidlist.indexOf(that.time[i].list[j].lopenid)].count = Number(that.time[i].list[j].scount) + Number(newPeopleList[slistOpenidlist.indexOf(that.time[i].list[j].lopenid)].count);
						newPeopleList[slistOpenidlist.indexOf(that.time[i].list[j].lopenid)].smoney = newPeopleList[slistOpenidlist.indexOf(that.time[i].list[j].lopenid)].count;
						newPeopleList[slistOpenidlist.indexOf(that.time[i].list[j].lopenid)].ymoney = newPeopleList[slistOpenidlist.indexOf(that.time[i].list[j].lopenid)].count;
					}
				}
			}
			that.totalpeoplelist = newPeopleList;
			console.log("最终数据：",this.totalpeoplelist);
		},
		//打开弹窗
		toShow(index,index1){
			let that = this;
			that.pindex = index;
			that.sindex = index1;
			that.scount = that.time[index].list[index1].scount;
			that.name = that.time[index].list[index1].lname;
			that.timeps = that.time[index].list[index1].givetime;
			that.show  = true;
		},
		//修改弹窗
		scountInput(e) {
			this.scount = e.detail.value;
			// 同步信息流---------------------------
			console.log(e.detail.value);
		},
		//保存
		setMoneySet(){
			let that  = this;
			that.time[that.pindex].list[that.sindex].scount = that.scount;
			that.show = false;
			that.totalMoney();
		},
		
		//确认提交数组
		confirm(){
			let that = this;
			console.log("数据")
			console.log("数据：",that.totalpeoplelist)
			uni.request({
				url:"https://zback.shixiaozhu.work/ShixiaozhuTest/orderParticipant/setLouMoneyByFuZe",
				header: {
				      'content-type': 'application/json'
				     },
				method:"POST",
				data: that.totalpeoplelist,
				success(res) {
					if(res.data.status==200){
						console.log("输出：",res.data.data)
					    // that.time = res.data.data;
						// that.totalMoney();
					}else{
						
					}
				}
			})
			
			
		}
	}
};
</script>

<style lang="less">
.mo {
	padding: 20rpx;
	display: flex;
	justify-content: space-between;
	border-bottom: 2rpx solid #f0f0f0;
	line-height: 40rpx;
}

.mo_01 {
	padding-left: 20rpx;
	box-sizing: border-box;
	width: 80%;
	height: 40rpx;
	overflow: hidden;
	border-left: 6rpx solid #ec521b;
	font-size: 32rpx;
	font-weight: bold;
}

.mo_01 span {
	color: #8e8e8e;
	font-weight: 100;
	font-size: 24rpx;
	padding-left: 20rpx;
}
.timeblock {
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	background-color: #ec521b;
}
.timeblock-time {
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 100%;
	// align-items: center;
	// justify-content: center;
	background-color: #aaffff;
	margin-bottom: 10rpx;
	padding: 0 20rpx;
}
.timeblock-people {
	margin-top: 10rpx;
	display: flex;
	width: 100%;
	height: 100%;
	flex-direction: column;
	// align-items: center;
	// justify-content: center;
	justify-content: space-between;
	background-color: #d6d4d4;
	margin-bottom: 10rpx;
	padding: 0 20rpx;
}
.peoplemoney {
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	background-color: #ec521b;
	padding: 0 20rpx;
}
.peoplemoney-people{
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	// flex-direction: column;
	margin-bottom: 20rpx;
	padding: 0 20rpx;
	justify-content: space-between;
	background-color: #ffaa00;
}
.login__info__item__button {
	margin: 60rpx auto;
	width: 690rpx;
	height: 80rpx;
	padding: 15rpx;
	border-radius: 5px;
	text-align: center;
	font-size: 32rpx;
	font-weight: bold;
	justify-content: center;
	align-items: center;
	margin-bottom: 20rpx;
}

.bottom-button {
	width: 100%;
	padding: 10rpx 0rpx;
	display: flex;
}
</style>
